package com.sieiot.goodknow.base.stable.api;

import org.springframework.util.StringUtils;

/**
 * 支撑前端可自由选择排序字段
 * @author lyh
 * @since 2021-07-28
 */
public class OrderByQO {

    /**
     * 用于查询排序的列名称
     */
    private String cloumnName;

    /**
     * 排序：升序:asc、降序:desc
     */
    private String orderType;


    /**
     * 是否配置了排序
     * @return true: 配置了排序
     */
    public boolean hasOrderBy() {
        return StringUtils.hasText(cloumnName) && StringUtils.hasText(orderType);
    }


    ////////////////////////// getter setter ////////////////

    public String getCloumnName() {
        return cloumnName;
    }

    public void setCloumnName(String cloumnName) {
        this.cloumnName = cloumnName;
    }

    public String getOrderType() {
        return orderType;
    }

    public void setOrderType(String orderType) {
        if (StringUtils.hasText(orderType)) {
            if ("asc".equalsIgnoreCase(orderType) || "desc".equalsIgnoreCase(orderType)) {
                this.orderType = orderType;
            } else {
                this.orderType = null;
            }
        }
        this.orderType = orderType;
    }


}
